<template>
  <div class="body" style="height: 100vh">
    <el-scrollbar ref="scroll" class="scrollbar-wrapper" wrap-style="overflow-x:hidden;">


    <div class="video-list-body" >
      <h3 class="title">{{this.title}}</h3>
      <el-row :gutter="10" class="el-row" style="justify-content: normal" >

        <el-col  :span="spanSize" v-for="(o) in tableData" :key="o.id" class="el-card">
          <el-card style="display: inline-block ;width: 100%" :body-style="{ padding: '0px' }" shadow="hover">
            <div class="video-thumbnail" @click="sunvdeo(o)">
              <img :src="'http://localhost:9091/images/video/'+o.imgurl" class="image">
              <div class="overlay">
                <i class="el-icon-video-play play-icon"></i>
              </div>
            </div>
            <div class="card-content">
              <h3 class="video-title">{{ o.sername }}</h3>
<!--              <p class="video-description">{{ o.des }}</p>-->
              <div class="video-info">
                <span class="video-author">作者: {{ o.uname }}</span>
              </div>
            </div>

          </el-card>
        </el-col>
      </el-row>
      <div class="pager">
        <el-pagination
            :page-size="8"
            :pager-count="1"
            layout="prev, pager, next"
            :total="total"
            @current-change="currentChange"
        >
        </el-pagination>
      </div>
    </div>

    <el-empty :description="暂无视频" v-show="tableData.length===0||tableData==undefined"></el-empty>
    </el-scrollbar>
  </div>
</template>

<script>import { getVlist, hisadd, listmyc } from "@/api";

export default {
  props: {
    tt: {
      type: String,
    },
    callback: {
      type: Function
    },
    gu: {
      type: Object
    },
    tui: {
      type: Number
    },
    cate: {
      type: Number
    },
    vlnow: {
      type: Number
    },
  },
  data() {
    return {
      title: '',
      activeIndex: '1',
      video: {},
      currentDate: new Date(),
      tableData: [],
      total: '',
      searchForm: {
        sername: ''
      },
      pageData: {
        pageNum: 1,
        pageSize: 8,
      },
    };
  },
  computed: {
    spanSize() {
      const width = window.innerWidth;
      if (width >= 1200) {
        return 6; // 4 cards per row
      } else if (width >= 992) {
        return 8; // 3 cards per row
      } else if (width >= 768) {
        return 12; // 2 cards per row
      } else {
        return 24; // 1 card per row on mobile
      }
    }
  },
  watch: {
    cate() {
      this.tableData = [];
      getVlist({ params: { ...this.pageData, category: this.cate } }).then(data => {
        this.tableData = data.data.data.list
        this.total = data.data.data.total|| 0;
      });
      this.title = "/分类";
    },
    tui() {
      this.getList();
      this.title = "推荐";
    },
    tt() {
      this.searchForm.sername = this.tt;
      this.getList();
      this.title = "搜索结果";
    },
    gu() {
      this.tableData = [];
      let x = this.gu;
      listmyc(x).then(data => {
        this.tableData = data.data.data;
      });
      this.title = "我的关注";
    }
  },
  methods: {
    getconten(){
      if (this.vlnow == 2) {
        getVlist({ params: { ...this.pageData, category: this.cate } }).then(data => {
          this.tableData = data.data.data.list;
          this.total = data.data.data.total || 0;
          this.title="分类"
        });
      } else if (this.vlnow == 3) {
        let x = this.gu;
        listmyc(x).then(data => {
          this.tableData = data.data.data;

        });
        this.title = "我的关注";
      } else {
        this.getList();
        this.title = "推荐";
      }
    },

    sunvdeo(val) {
      this.video = val;
      this.callback(this.video);
      hisadd({ vid: val.id, uid: this.$cookies.get("user").id });
      // console.log(this.$cookies.get("user").id, "uuuuuuuuuuuu");
    },
    currentChange(val) {
      this.pageData.pageNum = val;
      this.getconten()
    },
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
    },
    getList() {
      getVlist({ params: { ...this.pageData, ...this.searchForm } }).then((data) => {
        this.tableData = data.data.data.list;
        this.total = data.data.data.total || 0;
      });
    }
  },
  mounted() {
    this.$nextTick(() => {
   this.getconten()
    });
  }
}
</script>

<style scoped lang="less">
.title {
  font-size: 24px;
  color: #333;
  font-weight: bold;
  margin: 0;
  padding: 10px 0;
  background-color: transparent;
  border-radius: 8px;
}
.video-list-body {
  width: 85%;
  margin: auto;
  overflow-y: hidden;
  overflow-x: hidden;
}

.body {
  padding: 20px;
overflow-y: hidden;
}

.el-row {
  margin-top: 20px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;

}

.el-col {
  margin-bottom: 20px;
  box-sizing: border-box;
  border-radius: 12px 12px 12px 12px;

}

.el-card {


  border-radius: 8px;
  background-color: transparent;

}

.el-card:hover {
  border-radius: 12px 12px 12px 12px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.video-thumbnail {
  display: inline-block;
  position: relative;
  cursor: pointer;
  border-radius: 12px 12px 12px 12px;
  overflow: hidden;
  width: 100%; /* 确保图片宽度占满整个卡片 */

}

.video-thumbnail img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.video-thumbnail:hover img {
  transform: scale(1.05);
}

.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.video-thumbnail:hover .overlay {
  opacity: 1;
}

.play-icon {
  font-size: 48px;
  color: #fff;
}

.card-content {
  border: none; /* 去掉边框 */
  border-radius: 0; /* 去掉圆角 */
  padding: 16px; /* 保留内边距 */
  background-color: transparent; /* 设置透明背景 */
  height: 60%;
  margin-bottom: 16px;
}

.video-title {
  font-size: 1em;
  font-weight: bold;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  color: #333;
}

.video-description {
  font-size: 1em;
  color: #666;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.video-info {
  display: flex;
  align-items: center;
  font-size: 14px;
  color: #999;
}

.pager {
  position: relative;
  bottom: 10px;
}

.time {
  font-size: 13px;
  color: #999;
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.button {
  padding: 0;
  float: right;
}

.image {
  width: 100%;
  height: 200px;
  display: block;
  object-fit: cover;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both;
}

.video-author {
  font-size: 0.9em;
  color: #555;
}
</style>
